#include "MenuState.h"
#include "TextureManager.h"
#include "Game.h"
#include "MenuButton.h"
#include "LoaderParams.h"
#include "PlayState.h"


//const std::string MenuState::s_menuID = "MENU";

void MenuState::update(){
    for (int i = 0; i < m_gameObjects.size(); i++){
        m_gameObjects[i]->update();
    }
}

void MenuState::render(){
     for (int i = 0; i < m_gameObjects.size(); i++){
        m_gameObjects[i]->draw();
    }

}

bool MenuState::onEnter(){
    if (!TheTextureManager::Instance()->load("assets/play_button.png",
                                             "playbutton",
                                             TheGame::Instance()->getRenderer()
                )){
        return false;
    }
    if (!TheTextureManager::Instance()->load("assets/exit_button.png",
                                             "exitbutton",
                                             TheGame::Instance()->getRenderer()
                )){
        return false;
    }
    GameObject * button_play = new MenuButton();
    GameObject * button_exit = new MenuButton();

    m_gameObjects.push_back(button_play);
    m_gameObjects.push_back(button_exit);


    std::cout << "entering MenuState" << std::endl;
    return true;
}

bool MenuState::onExit(){
    for (int i = 0; i < m_gameObjects.size(); i++){
        m_gameObjects[i]->clean();
    }
    m_gameObjects.clear();
    TheTextureManager::Instance()
        ->clearFromTextureMap("playbutton");
    TheTextureManager::Instance()
        ->clearFromTextureMap("exitbutton");
    

    std::cout << "exiting MenuState" << std::endl;
    return true;
}

void MenuState::s_menuToPlay(){
    //std::cout << "Play button clicked 1" << std::endl;
    TheGame::Instance()->getStateMachine()->changeState(
            new PlayState());
}

void MenuState::s_exitFromMenu(){
    TheGame::Instance()->clean();
   // std::cout << "Exit button clicked 1" << std::endl;
}






























